import axios from 'axios';

const idCardReader = axios.create({
    baseURL: 'http://localhost:8989',
});

export async function readIdCard() {
    try {
        const response = await idCardReader.get('/api/ReadMsg');
        if (response.data?.code !== '0') {
            throw new Error(`读卡器返回错误: ${response.data?.code || '未知错误'}`);
        }
        return response.data;
    } catch (error) {
        if (error.code === 'ERR_NETWORK') {
            throw new Error('无法连接到身份证读卡器,请检查设备是否连接或是否开启读卡软件');
        }
        throw error; // 其他错误原样抛出
    }
}